/*
 * @Author: yyyyjinying
 * @Date: 2024-07-31 22:45:05
 * @LastEditTime: 2024-07-31 22:57:51
 * @LastEditors: yyyyjinying
 * @Description:
 * @FilePath: /heima-shop/src/services/order.ts
 * 可以输入预定的版权声明、个性签名、空行等
 */
// import type { OrderPreResult } from '@/types/order'
import { request } from '@/utils/http'
import type { OrderCreateParams, OrderCreateResult, OrderPreResult, OrderResult } from '@/types/order'
/**
 * 填写订单-获取预付订单
 */
export const getMemberOrderPreAPI = () => {
  return request<OrderPreResult>({
    method: 'GET',
    url: '/member/order/pre',
  })
}

/**
 * 填写订单-获取立即购买订单
 */
export const getMemberOrderPreNowAPI = (data: {
  skuId: string
  count: string
  addressId?: string
}) => {
  return request<OrderPreResult>({
    method: 'GET',
    url: '/member/order/pre/now',
    data,
  })
}
/**
 * 提交订单
 * @param data 请求参数
 */
export const postMemberOrderAPI = (data: OrderCreateParams) => {
  return request<OrderCreateResult>({
    method: 'POST',
    url: '/member/order',
    data,
  })
}
/**
 * 获取订单详情
 * @param id 订单id
 */
export const getMemberOrderByIdAPI = (id: string) => {
  return request<OrderResult>({
    method: 'GET',
    url: `/member/order/${id}`,
  })
}

/**
 * 填写订单-再次购买
 * @param id 订单id
 */
export const getMemberOrderRepurchaseByIdAPI = (id: string) => {
  return request<OrderPreResult>({
    method: 'GET',
    url: `/member/order/repurchase/${id}`,
  })
}


/**
 * 获取订单列表
 * @param data orderState 订单状态
 */
export const getMemberOrderAPI = (data: OrderListParams) => {
  return request<OrderListResult>({
    method: 'GET',
    url: `/member/order`,
    data,
  })
}

import type { PageParams } from '@/types/global'
/** 订单列表参数 */
export type OrderListParams = PageParams & { orderState: number }

/** 订单列表 */
export type OrderListResult = {
  /** 总记录数 */
  counts: number
  /** 数据集合    [ 订单信息 ] */
  items: OrderItem[]
  /** 当前页码 */
  page: number
  /** 总页数 */
  pages: number
  /** 页尺寸 */
  pageSize: number
}

/** 订单列表项 */
export type OrderItem = OrderResult & {
  /** 总件数 */
  totalNum: number
}
